#!/bin/bash

set -e

export ROOT_DIR=$(readlink -e $(dirname $0) | sed 's|/scripts||')

source ${ROOT_DIR}/scripts/common_pkg_build.sh

prepare_tarball

pushd ${ROOT_DIR}/${package}-${version}
cp -r ${ROOT_DIR}/pkg/debian .

current=$(echo ${version} | awk -F . '{printf("%d\n", (($1 * 100) + $2))}')
rename 's,([^-\.]*)(.*),${1}'"${current}"'${2},' debian/*odp*

sed -i "s:\(.*odp\)\([^\.]\|$\):\1${current}\2:g" debian/control
sed -i "s:\(.*odp\)\(.*\):\1${current}\2:g" debian/rules

if [ $(egrep "\.([a-z0-9]{8}\>|dirty)" .scmversion |wc -l) -gt 0 ]; then
	export DEBFULLNAME="Donald Duck"
	export DEBEMAIL="donald.duck@linaro.org"
	dch --newversion ${version}-1 --urgency low "not a official release!"
fi

debuild -us -uc
popd
popd
